package com.zyg.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.zyg.pojo.Cla;
import com.zyg.pojo.EchartsData;
import com.zyg.pojo.Grade;
import com.zyg.pojo.Role;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.io.Serializable;
import java.util.List;

@Mapper
public interface ClaMapper extends BaseMapper<Cla> {
    // 根据 entity 条件，查询全部记录
    @Override
    @Select("select cla_id,cla_name,grade_id from sys_cla")//一定要特别注意@One注解的使用，使用了@one就不用写连接表的sql语句
    @Results(id="claMap", value = {
            @Result(property="claId",column="cla_id"),
            @Result(property="claName",column="cla_name"),
            @Result(property="grade",column="grade_id",javaType= Grade.class,
            one=@One(select="com.zyg.dao.GradeMapper.selectById",fetchType = FetchType.LAZY )),

    })
    List<Cla> selectList(IPage<Cla> page, Wrapper<Cla> wrapper);
    @Override
    @Select("select * from sys_cla where cla_id=#{claId}")
    @Results(id="claMap1", value = {
            @Result(property="claId",column="cla_id"),
            @Result(property="claName",column="cla_name"),
            @Result(property="grade",column="grade_id",javaType= Grade.class,
                    one=@One(select="com.zyg.dao.GradeMapper.selectById",fetchType = FetchType.LAZY )),

    })
    Cla selectById(Serializable claId);
    @Select("select g.grade_name as name,count(*) as value from sys_cla c inner join sys_grade g on g.grade_id = c.grade_id group by c.grade_id" )
    List<EchartsData> getGradeIndexData();
}
